window.onload=function(){	
	$(".payList > a").on('click',function(){
		if($(".numberInt").val()>0){
			event.preventDefault();
			hint('您已经输入了购买量，请点击"支付"');
		}else{
			var $this=$(this);
			$this.toggleClass('pActive').siblings().removeClass('pActive');
		}
	})
	function onBridgeReady(data){
	   WeixinJSBridge.invoke(
	       'getBrandWCPayRequest', {
	           "appId":data.appId,     //公众号名称，由商户传入     
	           "timeStamp":data.timeStamp,         //时间戳，自1970年以来的秒数     
	           "nonceStr":data.nonceStr, //随机串     
	           "package":data.package,     
	           "signType":data.signType,         //微信签名方式：     
	           "paySign":data.paySign //微信签名 
	       }
	    //    function(res){     
	    //        if(res.err_msg == "get_brand_wcpay_request：ok" ) {
		   //         	hint("恭喜您，支付成功！");
		   //         	setTimeout(function(){
					// 	window.location.href = "/user/checkPayment?"+new Date().getTime();
					// },500);
	    //        	}
	    //    	}
	   	)
	}

	$(".payBtn").click(function(){
		var Money=0,Flow=0;
		if($(".numberInt").val()==0){
			Money=$(".pActive").children("span").eq(0).html();
			Flow=$(".pActive").children("span").eq(1).html();
		}else{
			Money=$(".numberInt").val()*100;
			Flow=$(".fluxBox").html()
		}
		$.ajax({
			url:"/api/device/pay",
			type:"post",
			dataType:"json",
			data:{
				money:Money,
				flow:Flow				
			},
			success:function(data){
				if(data.status.errCode == 0){
					if (typeof WeixinJSBridge == "undefined"){
					   if( document.addEventListener ){
					       document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
					   }else if (document.attachEvent){
					       document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
					       document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
					   }
					}else{
					   onBridgeReady(data.data);
					}
				}
				else{
					hint(data.status.message);
				}
			}
		});
	});
}